package com.bc.web.controller.org;

import java.util.ArrayList;
import java.util.List;

import com.bc.web.model.Account;
import com.bc.web.model.Merch;
import com.bc.web.model.OrgUser;
import com.fs.common.extend.FSController;

public class AccountController extends FSController {

	public void search() {
		OrgUser orgUser = (OrgUser) getSession().getAttribute("orgUser");
		List<Merch> merchList = Merch.dao.selectByOrgCode(orgUser.getOrgCode());
		List<String> accountNoList = new ArrayList<>();
		if (merchList == null || merchList.isEmpty()) {
			List<Account> accountList = new ArrayList<>(); 
			setAttr("accountList", accountList);
			render("account/accountList.html");
		} else {

			for (Merch merch : merchList) {
				accountNoList.add(merch.getCode());
			}
			List<Account> accountList = Account.dao.selectByAccountNo(accountNoList.toArray());
			for (Account item : accountList) {
				item.setBalance(Long.valueOf(item.get("sumBalance").toString()));
				item.setD0Balance(Long.valueOf(item.get("sumD0Balance").toString()));
			}
			setAttr("accountList", accountList);
			render("account/accountList.html");
		}
	}

}
